/**
 * @file:replace_container_of.c
 * @brief:算法替代container_of函数
 * @author:liaowx
 * @date:2019.08.02
 */
#include <stdio.h>

int main(int argc, char *argv[])
{
    struct test {
        int num;
        char ch;
    }t1 = {100,'c'};
    char *pch = &t1.ch;
    struct test *ptt = ({const typeof(((struct test *)0)->ch) *__ptmp = (pch);
                    (struct test *)((char *)__ptmp - ((size_t) &((struct test *)0)->ch)); });
 
    printf("num = %d\n", ptt->num);

    return 0;
}